﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using VietKinsNutrition.Bussiness;
using VietKinsNutrition.Common;

namespace VietKinsNutrition.UserControl
{
    public partial class FrmTblChitietkienthucnoitro : DevExpress.XtraEditors.XtraUserControl
    {

        ClsTbl_LoaikienthucnoitroBLL ClsTbl_Loaikienthucnoitrobll = new ClsTbl_LoaikienthucnoitroBLL();
        ClsTblChitietkienthucnoitroBLL ClsTblChitietkienthucnoitrobll = new ClsTblChitietkienthucnoitroBLL();
        
        public FrmTblChitietkienthucnoitro()
        {
            InitializeComponent();
        }

        private void FrmTblChitietkienthucnoitro_Load(object sender, EventArgs e)
        {
            ClsTbl_Loaikienthucnoitrobll.Bind_Combo(cboNhom);
            grdDS.GridControl.DataSource = ClsTblChitietkienthucnoitrobll.SelectAll();
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cboNhom.Text == "") return;
                if (cboNhom.SelectedItem == null) return;
                if (cboNhom.SelectedItem != null)
                {
                    ClsTblChitietkienthucnoitrobll.Bind_Grid(int.Parse(UserComboBoxItem.GetItemValue(cboNhom)), grdDS);
                }
            }
            catch { }
        }

        private void txtTimkiem_EditValueChanged(object sender, EventArgs e)
        {
            if (cboNhom.EditValue == null)
            {
                grdDS.GridControl.DataSource = ClsTblChitietkienthucnoitrobll.GetByName(txtTimkiem.Text);
            }
            else
            {
                grdDS.GridControl.DataSource = ClsTblChitietkienthucnoitrobll.GetByNhomkienthucIdandName(int.Parse(UserComboBoxItem.GetItemValue(cboNhom)), txtTimkiem.Text);
            }
        }

        private void grdDS_DoubleClick(object sender, EventArgs e)
        {
            if (grdDS.RowCount > 0)
            {
                txtTieude.Text = grdDS.GetFocusedRowCellValue("Tieude").ToString();
                //TxtNoidung.Text = DG_Nhomkienthucnoitro.Rows[DG_Nhomkienthucnoitro.CurrentRow.Index].Cells["Noidung"].Value.ToString();
                object obj = grdDS.GetFocusedRowCellValue("Noidung").ToString();
                webBrowser1.DocumentText = grdDS.GetFocusedRowCellValue("Noidung").ToString();
            }
        }

    }
}
